import { defineStore } from "pinia";

export const useCommonStore = defineStore("common", {
  state: () => ({
    baseImageUrl:
      "https://siyuan-wx-1251107588.cos.ap-beijing.myqcloud.com/sy-qing-chaungye/",
    cityList: [],
    storeList: [],
    storeAndCityInfo: {}, // 当前用户默认门店和城市信息
    locationInfo: {}, // 当前用户位置信息
  }),

  actions: {
    setCityList(list) {
      this.cityList = list;
    },
    setStoreList(list) {
      console.log("storeList1", list);
      this.storeList = list;
    },
    setStoreAndCityInfo(info) {
      this.storeAndCityInfo = info;
      uni.setStorageSync("storeAndCityInfo", info);
    },
    // 开发中，敬请期待提示
    showCommonSoon() {
      uni.navigateTo({
        url: "/pages/subpackages/mineCenter/common-soon",
      });
    },

    setLocationInfo(info) {
      this.locationInfo = info;
      uni.setStorageSync("locationInfo", info);
    },
    // 初始化数据
    initStateFromStorage() {
      const storeAndCityInfo = uni.getStorageSync("storeAndCityInfo");
      if (storeAndCityInfo) this.storeAndCityInfo = storeAndCityInfo;
      
      const locationInfo = uni.getStorageSync("locationInfo");
      if (locationInfo) this.locationInfo = locationInfo;
    }
  }
});
